package com.wallet.service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wallet.dao.TransactionDao;
import com.wallet.entity.Transaction;
import com.wallet.entity.example.TransactionExample;
import com.wallet.entity.result.JsonResult;
import com.wallet.entity.result.ResultCode;
import com.wallet.service.BaseService;

@Service
public class TransactionServiceImpl implements BaseService<Transaction, TransactionExample> {

	@Autowired
	TransactionDao transactionDao;
	
	@Override
	public int save(Transaction t) {
		return transactionDao.insert(t);
	}

	@Override
	public int insertBatch(List<Transaction> list) {
		return transactionDao.insertBatch(list);
	}

	@Override
	public int del(Integer id) {
		return transactionDao.deleteByPrimaryKey(id);
	}

	@Override
	public int upd(Transaction t) {
		return transactionDao.updateByPrimaryKey(t);
	}

	@Override
	public Transaction getDetail(Integer id) {
		return transactionDao.selectByPrimaryKey(id);
	}

	@Override
	public JsonResult showPage(Integer page, Integer size) {
		JsonResult result=new JsonResult();
		PageHelper.startPage(page, size);
		Map<String, Object>data=new HashMap<String, Object>();
		List<Transaction> list=transactionDao.selectAll();
		Integer total=transactionDao.selectCount();
		PageInfo<Transaction> transactions=new PageInfo<Transaction>(list);
		data.put("items", transactions.getList());
		data.put("total", total);
		result.setData(data);
		result.setCode(ResultCode.SUCCESS.getVal());
		return result;
	}

	@Override
	public Integer getCount() {
		return transactionDao.selectCount();
	}

	@Override
	public List<Transaction> selectAll() {
		return transactionDao.selectAll();
	}

	@Override
	public List<Transaction> selectByExample(TransactionExample example) {
		// TODO Auto-generated method stub
		return null;
	}

}
